'use strict';
var ApproveDetail = {
	data: function data() {
		return {
			loginInfo: {},
			EnjoyOA: '',
			EnjoyRMIS: '',
			EnjoyMall: '',
			EnjoyCRM: '',
			ProjectName: '',
			MdCode: '',
			AppId: '',
			AppRecvId: '',
		}
	},
	mounted: function mounted() {
		const self = this;
		mui.plusReady(function() {
			// #ifdef APP-PLUS
			var handle = plus.webview.currentWebview();
			// #endif
			self.AppId = handle.selectedItem.AppId;
			self.AppRecvId = handle.selectedItem.AppRecvId;
			self.loginInfo = JSON.parse(handle.selectedItem.loginInfo);
			self.EnjoyOA = handle.selectedItem.EnjoyOA;
			self.EnjoyRMIS = handle.selectedItem.EnjoyRMIS;
			self.EnjoyMall = handle.selectedItem.EnjoyMall;
			self.EnjoyCRM = handle.selectedItem.EnjoyCRM;
			self.ProjectName = handle.selectedItem.ProjectName;
			self.MdCode = handle.selectedItem.MdCode;
			self.SetApprovePage(JSON.parse(handle.selectedItem.ObjectData))
		})
	},
	methods: {
		SetApprovePage: function SetApprovePage(ObjectData) {
			const self = this;
			if (ObjectData && ObjectData.RetType) {
				if (ObjectData.RetType == 3) {
					$('#approve-detail').css('display', 'none');
					$('#divContent').hide();
					$("#divDetail").empty();
					$('iframe').attr('src',
						`${self.loginInfo.OAOutIp}/#/flow?appid=${self.AppId}&recvid=${self.AppRecvId}&mode=view&token=${self.loginInfo.OARefreshToken}`
					);
					document.getElementById('ifmContent').style.height = 100 + 'vh';
				} else if (ObjectData.RetType == 2) {
					if (ObjectData.BillContent != null && ObjectData.BillContent != undefined && ObjectData
						.BillContent != "") {
						$('iframe').css('display', 'none');
						document.getElementById('divDetail').style.height = 100 +
							'vh';
						$('#divContent').show();
						$("#divDetail").empty();
						$("#approve-detail").hide();
						var divDetail = document.getElementById('divDetail');
						var detailContent = unescape(ObjectData.BillContent);
						detailContent = detailContent.replace(/; top/g, "px; top");
						detailContent = detailContent.replace(/;Height/g,
							"px;Height");
						detailContent = detailContent.replace(/;width/g,
							"px;width");
						detailContent = detailContent.replace(/pxpx/g, "px");
						if (self.ProjectName.indexOf('RMIS') >= 0 || self.ProjectName.indexOf('rmis') >= 0 ||
							self.ProjectName.indexOf('Rmis') >= 0) {
							const enjoyUrl = self.EnjoyRMIS.replace('/Enjoy/Service', '');
							const _url = enjoyUrl + '/File/GetEFormBgImg/'

							divDetail.innerHTML = detailContent.replace(
								/http:\/\/[^\s]*EFormGuid[^\s]*Type=Bg/g, _url + self.MdCode);
						} else if (self.ProjectName.indexOf('Mall') >= 0 || self.ProjectName.indexOf('mall') >=
							0 ||
							self.ProjectName.indexOf('百购') >= 0) {
							const enjoyUrl = self.EnjoyMall.replace('/Enjoy/Service', '');
							divDetail.innerHTML = (detailContent.replace(
									/http:\/\/[^\s]*EFormGuid[^\s]*Type=Bg/g,
									enjoyUrl + '/File/GetEFormBgImg/' + self.MdCode))
								.replace(
									/http:\/\/[^\s]*DownLoadImage/g, enjoyUrl + '/File/DownLoadImage');
						} else if (self.ProjectName.indexOf('CRM') >= 0 || self.ProjectName.indexOf('crm') >=
							0 ||
							self.ProjectName.indexOf('Crm') >= 0) {
							const enjoyUrl = self.EnjoyCRM.replace('/Enjoy/Service', '');
							const _url = enjoyUrl + '/File/GetEFormBgImg/';
							divDetail.innerHTML = detailContent.replace(
								/http:\/\/[^\s]*EFormGuid[^\s]*Type=Bg/g, _url + self.MdCode);
						} else {
							const enjoyUrl = self.EnjoyOA.replace('/Enjoy/Service', '');
							divDetail.innerHTML = (detailContent.replace(
									/http:\/\/[^\s]*EFormGuid[^\s]*Type=Bg/g,
									enjoyUrl + '/File/GetEFormBgImg/' + self.MdCode))
								.replace(
									/http:\/\/[^\s]*DownLoadImage/g, enjoyUrl + '/File/DownLoadImage');
						}
					} else {
						mui.toast('暂无数据！');
					}
				} else if (ObjectData.RetType == 1) {
					if (ObjectData.BillContent != null && ObjectData.BillContent != undefined && ObjectData
						.BillContent != "") {
						$('iframe').css('display', 'none');
						$('#approve-detail').show();
						$("#approve-detail").empty();
						$('#divContent').hide();
						var detailContent = ObjectData.BillContent;
						$("#approve-detail").append(detailContent);
						document.getElementById('approval-body').style.height =
							100 + 'vh';
					} else {
						mui.toast('暂无数据！');
					}
				} else if (ObjectData.RetType == 0) {
					mui.toast('暂无数据！');
				} else {
					mui.toast('暂无数据！');
				}
			}
		}
	}
}
var Ctor = Vue.extend(ApproveDetail);
new Ctor().$mount('#approval');